package com.project.server.operate;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.common.utils.poi.ExcelUtil;
import com.project.server.domain.operate.TOperateEmergency;
import com.project.server.service.operate.ITOperateEmergencyService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 运营管理应急处理Controller
 *
 * @author project
 * @date 2021-06-29
 */
@RestController
@RequestMapping("/server/emergency")
public class TOperateEmergencyController extends BaseController {

    @Resource
    private ITOperateEmergencyService tOperateEmergencyService;

    /**
     * 查询运营管理应急处理列表
     */
    @PreAuthorize("@ss.hasPermi('server:emergency:list')")
    @GetMapping("/list")
    public TableDataInfo list(TOperateEmergency tOperateEmergency) {
        startPage();
        List<TOperateEmergency> list = tOperateEmergencyService.selectTOperateEmergencyList(tOperateEmergency);
        return getDataTable(list);
    }



    /**
     * 导出运营管理应急处理列表
     */
    @PreAuthorize("@ss.hasPermi('server:emergency:export')")
    @Log(title = "运营管理应急处理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TOperateEmergency tOperateEmergency) {
        List<TOperateEmergency> list = tOperateEmergencyService.selectTOperateEmergencyDelTags(tOperateEmergency);
        ExcelUtil<TOperateEmergency> util = new ExcelUtil<TOperateEmergency>(TOperateEmergency.class);
        return util.exportExcel(list, "应急处理列表");
    }

    /**
     * 获取运营管理应急处理详细信息
     */
    @PreAuthorize("@ss.hasPermi('server:emergency:query')")
    @GetMapping(value = "/{emergencyId}")
    public AjaxResult getInfo(@PathVariable("emergencyId") Long emergencyId) {
        return AjaxResult.success(tOperateEmergencyService.selectTOperateEmergencyById(emergencyId));
    }

    /**
     * 新增运营管理应急处理
     */
    @PreAuthorize("@ss.hasPermi('server:emergency:add')")
    @Log(title = "运营管理应急处理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TOperateEmergency tOperateEmergency) {
        return toAjax(tOperateEmergencyService.insertTOperateEmergency(tOperateEmergency));
    }

    /**
     * 修改运营管理应急处理
     */
    @PreAuthorize("@ss.hasPermi('server:emergency:edit')")
    @Log(title = "运营管理应急处理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TOperateEmergency tOperateEmergency) {
        return toAjax(tOperateEmergencyService.updateTOperateEmergency(tOperateEmergency));
    }

    /**
     * 删除运营管理应急处理
     */
    @PreAuthorize("@ss.hasPermi('server:emergency:remove')")
    @Log(title = "运营管理应急处理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{emergencyIds}")
    public AjaxResult remove(@PathVariable Long[] emergencyIds) {
        return toAjax(tOperateEmergencyService.deleteTOperateEmergencyByIds(emergencyIds));
    }
}
